/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package my.presentation;

import entities.Uzivatel;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author Bjelor
 */
@ManagedBean(name = "RegistraceView")
@ViewScoped
public class RegistraceView {

    private String username;
    private String password;
    
    private String passcheck;
    
    private String jmeno;
    private String prijmeni;
    
    @ManagedProperty(value="#{PrihlaseniView}")
    private PrihlaseniView prihlaseni;

    //must povide the setter method
    public void setPrihlaseni(PrihlaseniView prihlaseni) {
            this.prihlaseni = prihlaseni;
    }

    public String getPasscheck() {
        return passcheck;
    }

    public void setPasscheck(String passcheck) {
        this.passcheck = passcheck;
    }

    public String getJmeno() {
        return jmeno;
    }

    public void setJmeno(String jmeno) {
        this.jmeno = jmeno;
    }

    public String getPrijmeni() {
        return prijmeni;
    }

    public void setPrijmeni(String prijmeni) {
        this.prijmeni = prijmeni;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public String register(){
        if((password != null) && (passcheck != null)){ 
            if(password.equals(passcheck)){
                //Uzivatel user = new Uzivatel(Long.MIN_VALUE, username, password, null);
                //prihlaseni.getAuth().registrace(user);
                prihlaseni.submitLogin();
                prihlaseni.setUsername(username);
                return "index";
            } else {
                return "";
            }  
        } else {
            return "";
        }
    }

    /**
     * Creates a new instance of RegistraceView
     */
    public RegistraceView() {
        username = jmeno = prijmeni = password = passcheck = "";
    }
    
}
